package com.fs.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fs.entity.*;
import com.fs.mapper.MaterialsMapper;
import com.fs.service.IReviewersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-06-12
 */
//审核人员端

@RestController
@RequestMapping("/reviewers")
public class ReviewersController {
    @Autowired
    IReviewersService reviewersService;
    @Autowired
    MaterialsMapper materialsMapper;

    //登录
    @PostMapping("/login")
    public boolean login(@RequestBody Reviewers reviewer) {
        LambdaQueryWrapper<Reviewers> lambdaQueryWrapper = new LambdaQueryWrapper<Reviewers>();
        lambdaQueryWrapper.eq(Reviewers::getRname, reviewer.getRname());
        lambdaQueryWrapper.eq(Reviewers::getRpassword, reviewer.getRpassword());
        Reviewers one = reviewersService.getOne(lambdaQueryWrapper);
        if (one != null) {
            return true;
        }
        return false;
    }

    //注册
    @PostMapping("/register")
    public boolean register(@RequestBody Reviewers reviewer) {
        System.out.println("==============================");
        LambdaQueryWrapper<Reviewers> lambdaQueryWrapper = new LambdaQueryWrapper<Reviewers>();
        lambdaQueryWrapper.eq(Reviewers::getRname, reviewer.getRname());
        Reviewers one = reviewersService.getOne(lambdaQueryWrapper);
        if (one == null) {
            boolean isSuccessful = reviewersService.save(reviewer);
            return isSuccessful;
        }
        return false;
    }
    //修改个人信息
    @PostMapping("/updatereviewers")
    public boolean updatereviewers(@RequestBody Reviewers reviewer) {
        boolean isSuccessful = reviewersService.updateById(reviewer);
        return isSuccessful;
    }

    //查询工作进度
    @GetMapping("/queryStage")
    public Map queryStage(){
        HashMap<String, List<Materials>> map = new HashMap<>();
        LambdaQueryWrapper<Materials> lambdaQueryWrapper1 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper1.eq(Materials::getState,0);
        List notPass = materialsMapper.selectList(lambdaQueryWrapper1);
        map.put("未审核的材料",notPass);
        LambdaQueryWrapper<Materials> lambdaQueryWrapper2 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper2.eq(Materials::getState,1);
        List pass = materialsMapper.selectList(lambdaQueryWrapper2);
        map.put("已审核的材料",pass);
        return map;
    }

    //查询被分配的材料


    //材料审核


//    //修改审核结果
//    @PutMapping("/updateMaterialState")
//    public Boolean updateMaterialState(Materials materials){
//        int count = materialsMapper.updateById(materials);
//        if(count>0){
//            return true;
//        }
//        return false;
//    }
}
